package org.tigris.subversion.svnant.commands;

import java.io.File;
import java.io.FileFilter;
import org.tigris.subversion.svnant.SvnAntUtilities;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNClientException;

public class Ignore extends SvnCommand
  implements FileFilter
{
  private static final String MSG_CANT_ADD_FILE = "Can't add file %s to svn:ignore";
  private static final String MSG_CANT_ADD_PATTERN = "Can't add pattern %s to svn:ignore for %s";
  private File file = null;
  private File dir = null;
  private boolean recurse = false;
  private String pattern;

  public void execute()
  {
    if (this.file != null)
      svnIgnoreFile(this.file);
    if (this.dir != null)
      svnIgnorePattern(this.dir, this.recurse);
  }

  protected void validateAttributes()
  {
    SvnAntUtilities.attrsNotSet("file, dir", true, new Object[] { this.file, this.dir });
    if (this.dir != null)
    {
      SvnAntUtilities.attrIsDirectory("dir", this.dir);
      SvnAntUtilities.attrNotNull("pattern", this.pattern);
    }
    if (this.file != null)
    {
      SvnAntUtilities.attrIsFile("file", this.file);
      SvnAntUtilities.attrNull("pattern", this.pattern);
    }
  }

  private void svnIgnoreFile(File paramFile)
  {
    try
    {
      getClient().addToIgnoredPatterns(paramFile.getParentFile(), paramFile.getName());
    }
    catch (SVNClientException localSVNClientException)
    {
      throw ex(localSVNClientException, "Can't add file %s to svn:ignore", new Object[] { paramFile.getAbsolutePath() });
    }
  }

  private void svnIgnorePattern(File paramFile, boolean paramBoolean)
  {
    svnIgnorePattern(paramFile);
    if (paramBoolean)
    {
      File[] arrayOfFile = paramFile.listFiles(this);
      for (int i = 0; i < arrayOfFile.length; i++)
        svnIgnorePattern(arrayOfFile[i], true);
    }
  }

  public boolean accept(File paramFile)
  {
    return (paramFile.isDirectory()) && (!paramFile.getName().equals(getClient().getAdminDirectoryName()));
  }

  private void svnIgnorePattern(File paramFile)
  {
    try
    {
      getClient().addToIgnoredPatterns(paramFile, this.pattern);
    }
    catch (SVNClientException localSVNClientException)
    {
      throw ex(localSVNClientException, "Can't add pattern %s to svn:ignore for %s", new Object[] { this.pattern, paramFile.getAbsolutePath() });
    }
  }

  public void setFile(File paramFile)
  {
    this.file = paramFile;
  }

  public void setDir(File paramFile)
  {
    this.dir = paramFile;
  }

  public void setRecurse(boolean paramBoolean)
  {
    this.recurse = paramBoolean;
  }

  public void setPattern(String paramString)
  {
    this.pattern = paramString;
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.commands.Ignore
 * JD-Core Version:    0.6.0
 */